package com.twu.biblioteca;

public class LoggedUserInterface implements UserInterface{
    private Console console;

    LoggedUserInterface() {
        console = new Console();
    }
    @Override
    public void displayMenu() {
        console.write("\n\n\tMenu\n" +
                "  1.List Books\n" +
                "  2.Checkout book\n" +
                "  3.Return book\n" +
                "  4.List Movie\n" +
                "  5.Checkout Movie\n" +
                "  6.Return Movie\n" +
                "  7.View Profile\n" +
                "  8.Quit\n\n");
    }

    @Override
    public int getUserChoice() {
        console.write("Enter choice....");
        int input;
        try {
            input = console.readInteger();
        } catch (Exception e) {
            return getUserChoice();
        }
        return input;
    }

    @Override
    public void processRequest(BibliotecaApp bibliotecaApp, int choice) {
        LoggedUserChoice userChoice = LoggedUserChoice.values()[choice - 1];
        userChoice.processRequest(bibliotecaApp);
    }

    @Override
    public int quit() {
        return LoggedUserChoice.QUIT.getIndex();
    }

    @Override
    public void displayWelcomeMessage(String libraryName) {
        console.write("Welcome to " + libraryName);
    }
}
